<template>
  <div class="byd">
    <div class="login">
      <h3>后台管理系统</h3>
      <el-form :model="form" :rules="rules" ref="from">
        <el-form-item prop="adminname">
          <el-input v-model="form.adminname">
            <template #prefix>
              <el-icon><UserFilled /></el-icon>
            </template>
          </el-input>
        </el-form-item>
        <!-- ---------------------- -->
        <el-form-item prop="password">
          <el-input v-model="form.password" type="password" show-password>
            <template #prefix>
              <el-icon><Lock /></el-icon>
            </template>
          </el-input>
        </el-form-item>
        <!-- --------------------- -->
        <el-form-item>
          <el-button type="primary" @click="submitForm"> 登录 </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import { Login } from "../service/admin.js";
// import { UserFilled } from "@element-plus/icons-vue";
export default {
  components: {
    // UserFilled,
  },
  data() {
    return {
      form: {
        adminname: "",
        password: "",
      },
      rules: {
        adminname: [
          {
            required: true,
            message: "请输入用户名",
            trigger: "blur",
          },
        ],
        password: [
          {
            required: true,
            message: "请输入密码",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    submitForm() {
      let formEl = this.$refs.from;
      if (!formEl) return;
      formEl.validate((valid) => {
        if (valid) {
          Login(this.form).then((res) => {
            if (res.code == 200) {
              this.$store.commit("setUserInfo", res.data);
              this.$router.push("/home");
            }
          });
        } else {
          return false;
        }
      });
    },
  },
};
</script>

<style scoped>
.byd {
  width: 100vw;
  height: 100vh;
  background: url(../../public/gj.gif) center center no-repeat;
}
.login {
  width: 350px;
  height: 280px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 10px;
  background-color: rgb(102, 102, 102, 0.3);
  border-radius: 15px;
}
.el-input {
  margin: 10px;
}
.login > h3 {
  font-size: 20px;
  line-height: 20px;
  width: 100%;
  text-align: center;
  color: #fff;
}
.login button {
  width: 40%;
  margin: 0 auto;
}
</style>
